<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 二叉搜索树的个数 
            i个节点构建二叉搜索树个数为dp[i]
            dp[i]=dp[0]*dp[i-1]+dp[1]*dp[i-2]+dp[2]*dp[i-3]
            */
            var numTrees = function (n) {
                let dp = new Array(n + 1).fill(0)
                dp[0] = dp[1] = 1
                for (let i = 2; i <= n; i++) {
                    for (let j = 0; j < i; j++) {
                        dp[i] += dp[j] * dp[i - j - 1]
                    }
                }
                return dp[dp.length - 1]
            }
            numTrees(3)
        </script>
    </body>
</html>
